package com.ss.android.pay;

import android.app.Activity;
import android.os.Handler;
import android.os.Looper;

import com.bytedance.common.utility.Logger;
import com.tencent.mm.opensdk.openapi.IWXAPI;

import java.util.HashMap;
import java.util.Map;

public final class k {
    private static k c;
    l a;
    Map b;

    public k() {

        this.b = new HashMap();
        new Handler(Looper.getMainLooper());
    }

    public static k a() {
        if (k.c == null) {
            k.c = new k();
        }

        return k.c;
    }

    public final l a(Activity arg5, IWXAPI arg6, String arg7, j arg8) throws WXNotInstalledException, UnsupportedPayException {
        int v3 = 2;
        this.a = null;
        h v0 = h.a(arg7);
        this.a = null;
        if (v0.j != v3 && v0.j != 1) {
            throw new UnsupportedPayException();
        }

        if (v0.j == 1) {
            if (arg6 != null && (arg6.isWXAppInstalled())) {
                this.a = new m(arg6, v0, arg8);
                this.b.put(v0.e, this.a);
            } else {
                throw new WXNotInstalledException();
            }
        } else {
            if (v0.j != v3) {
            } else if (arg5 == null) {
            } else {
                this.a = new b(arg5, v0, arg8);
            }
        }

        return this.a;
    }

    final void a(l arg3) {
        if (arg3 == this.a) {
            this.a = null;
            if (Logger.debug()) {
                Logger.d("PaySession", "end session");
            }
        }

        if ((arg3 instanceof m)) {
            this.b.remove(((m) arg3).c());
        }
    }
}

